<?php

namespace App\Http\Traits;

trait ApiReturn{
    /**
     * 错误返回
     *
     * @param $code
     * @param $msg
     * @param string $data
     * @return \Illuminate\Http\JsonResponse
     */
    protected function err($code,$msg,$data=''){
        return response()->json(['code' => $code, 'msg' => $msg,'data' => $data])->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

    /**
     * 成功返回
     *
     * @param $data
     * @param string $msg
     * @return \Illuminate\Http\JsonResponse
     */
    protected function succ($data,$msg=''){
        return response()->json(['code' => '00000', 'data' => $data,'msg'=>$msg])->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }
}
